package com.ddwl.common.util;

import ch.hsr.geohash.WGS84Point;
import ch.hsr.geohash.util.VincentyGeodesy;
import com.ddwl.schema.model.Location;

/**
 * 距离计算工具
 *
 * @author Fu Zhaohui
 */
public class DistanceUtil {

    public static double distance(double fooLat, double fooLng, double barLat, double barLng) {
        WGS84Point foo = new WGS84Point(fooLat, fooLng);
        WGS84Point bar = new WGS84Point(barLat, barLng);
        return VincentyGeodesy.distanceInMeters(foo, bar) / 1000.0D;
    }

    public static double distance(Location loc1, Location loc2) {
        WGS84Point foo = new WGS84Point(loc1.getLat(), loc1.getLng());
        WGS84Point bar = new WGS84Point(loc2.getLat(), loc2.getLng());
        return VincentyGeodesy.distanceInMeters(foo, bar);
    }
}